<template>
  <!-- 台账管理-其他 -->
  <div class="RightFzjkDetails bigTableStyle">
    <div class="box" v-if="isShow == 'station' || isShow == 'area'">
      <div class="elForm-box">
        <el-form ref="elForm" :model="formData" size="medium" label-width="1.4rem">
          <el-row>
            <el-col :span="6">
              <el-form-item label="变电站名称:" prop="time">
                <el-select
                  v-model="formData.cities"
                  placeholder
                  clearable
                  disabled
                  :style="{ width: '100%' }"
                  filterable
                >
                  <el-option
                    v-for="(item, index) in bdzmc"
                    :key="index"
                    :label="item.stationName"
                    :value="item.stationId"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="设备类型:" prop>
                <el-select
                  v-model="formData.substation"
                  placeholder
                  clearable
                  filterable
                  :style="{ width: '100%' }"
                >
                  <el-option
                    v-for="(item, index) in getAreaList"
                    :key="index"
                    :label="item.areaName"
                    :value="item.areaId"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="设备名称:" prop="source">
                <el-input v-model="formData.manufacturer" placeholder="请输入" />
              </el-form-item>
            </el-col>
            <el-col :span="5" :offset="1">
              <el-button type="primary" @click="init">查询</el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <div class="inspection-report-index-btn">
                <el-button type="primary" @click="submitForm">新建</el-button>
                <el-button type="primary" @click="cutOut">删除</el-button>
                <el-button type="primary" @click="modify">修改</el-button>
                <el-button type="primary" @click="remoteMaintenance('远程维护')">远程维护</el-button>
                <!-- <el-button type="primary" @click="remoteBoot">远程启动</el-button>
                <el-button type="primary" @click="remoteStop">远程停止</el-button>-->
              </div>
            </el-col>
            <el-col :span="4">
              <div class="inspection-report-index-btn" style="margin-left: 0.15rem;">
                <el-button type="primary" @click="deviceStatistics">设备统计</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="tableed bigTableStyle">
        <el-table
          border
          :data="tableData"
          height="100%"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
          style="width: 100%;"
        >
          <el-table-column type="selection" width="50"></el-table-column>
          <el-table-column prop="myIndex" label="序号" width="60"></el-table-column>
          <el-table-column prop="bdzmc" label="变电站名称" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop label="设备类型" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="ceshi" label="设备名称" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop label="安装位置" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop label="运行状态" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop label="生产厂家" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop label="投运日期" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column label="操作">
            <span
              @click="remoteMaintenance('性能参数查看')"
              :style="{ color: 'skyblue', cursor: 'pointer' }"
            >操作</span>
          </el-table-column>
        </el-table>
      </div>
      <div class="paged elPaginationStyle">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pages.page"
          :page-sizes="[10, 15, 20]"
          :page-size="pages.pageSize"
          layout="total,prev, pager, next,sizes, jumper"
          :total="pages.totalSize"
        ></el-pagination>
      </div>
      <!-- 新增和修改的弹窗 -->
      <el-dialog
        :title="PopUptitle"
        :visible.sync="dialogVisible"
        width="8.49rem"
        :before-close="handleClose"
      >
        <RightZxjcAdd
          :multipleSelection="multipleSelection"
          :PopUptitle="PopUptitle"
          @initList="init()"
          @determine="handleClose"
          v-if="dialogVisible"
        />
      </el-dialog>
      <!-- 模板导入 -->
      <input
        id="file0"
        type="file"
        name="file"
        v-if="isShowFile"
        accept="application/vnd.ms-excel"
        @change="fileUpload"
      />
    </div>
    <div class="box" v-if="isShow == 'dw' || isShow == 'xcompany' || isShow == 'vo'">
      <HomeList />
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue, Watch, Prop } from "vue-property-decorator";
import time from "@/utils/time.js";
import RightZxjcAdd from "./RightZxjcAdd.vue";
import HomeList from "../RightFzjk/HomeList.vue";

import { ParameterManagementModule } from "@/store/modules/ParameterManagement";
import { log } from "three";
@Component({
  components: { RightZxjcAdd, HomeList },
})
export default class RightFzjkDetails extends Vue {
  @Prop({ type: String })
  isTogg: any;
  //弹框状态
  public dialogVisible: boolean = false;

  //弹框title
  public PopUptitle: string = "";

  //搜索框from表单数据
  formData = {
    cities: "",
    substation: "",
    manufacturer: "",
    system: "",
    sccj: "",
    areaName: "",
  };
  bdzmc = [];
  jclx = [
    { jclxName: "可见光摄像机", jclxId: "0" },
    { jclxName: "红外摄像机", jclxId: "1" },
  ];
  //选择数据
  public multipleSelection: Array<any> = [];

  //table表格相关事件数据
  tableData = [];
  //分页数据事件相关
  pages = {
    pageSize: 10,
    page: 1,
    totalSize: 0,
  };

  //切换right页面
  deviceStatistics() {
    this.$emit("changeIsTogg");
  }

  get isShow() {
    // console.log(ParameterManagementModule.TreeId);
    return ParameterManagementModule.TreeId;
  }
  get treeSbSsdsId() {
    return ParameterManagementModule.treeSbIdName.ssdsId;
  }
  //树图点击的ID
  get id() {
    return ParameterManagementModule.treeSbIdName.id;
  }
  get parentId() {
    return ParameterManagementModule.treeSbIdName.parentId;
  }
  get bdzId() {
    return ParameterManagementModule.treeSbIdName.bdzId;
  }
  get treeId() {
    return ParameterManagementModule.treeSbIdName.treeId;
  }
  get Treeid() {
    return ParameterManagementModule.TreeId;
  }
  get getAreaList() {
    return ParameterManagementModule.getAreaList;
  }
  tableid = "";
  //表格数据
  handleSelectionChange(val: any) {
    this.multipleSelection = val;
    this.tableid = "";
    this.multipleSelection.map((item: any) => {
      this.tableid = this.tableid + "," + item.devid;
    });
    this.tableid = this.tableid.substr(1);
    // console.log(this.multipleSelection);
  }
  //   分页
  handleSizeChange(val: any) {
    // console.log(`每页 ${val} 条`);
    this.pages.pageSize = val;
    this.init();
  }
  // 分页事件
  handleCurrentChange(val: any) {
    this.pages.page = val;
    // console.log(this.pages);

    this.init();
  }
  tableRowClassName({ row, rowIndex }: any): string {
    // console.log(row, rowIndex);
    if (rowIndex % 2 === 0) {
      return "row1";
    } else {
      return "row2";
    }
  }
  //删除
  cutOut() {
    // console.log("删除");
    if (this.multipleSelection.length > 0) {
      this.$confirm("是否删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          (this as any).$services
            .deleteRobot({
              data: { ids: this.tableid, stationId: this.bdzId },
              method: "delete",
            })
            .then((result: any) => {
              //  console.log(result);
              if (result.code === 200) {
                this.$message({
                  showClose: true,
                  message: result.message,
                  type: "success",
                });
                this.init();
              } else {
                this.$message({
                  showClose: true,
                  message: result.message,
                  type: "warning",
                });
              }
            })
            .catch((err: object) => {
              //  console.log(err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    } else {
      this.$message({
        showClose: true,
        message: "至少选择一条",
        type: "warning",
      });
    }
  }
  //新建
  submitForm() {
    this.PopUptitle = "新建";
    this.dialogVisible = true;
  }
  // 修改
  modify() {
    this.PopUptitle = "修改";
    if (this.multipleSelection.length != 1) {
      this.$message({
        type: "warning",
        message: "请勾选一条数据",
      });
    } else {
      this.dialogVisible = true;
    }
  }
  //关闭弹框
  handleClose() {
    this.dialogVisible = false;
  }
  //是否展示文件 选择上传
  isShowFile = true;
  //模板导入
  mbgx() {
    document.getElementById("file0").click();
  }
  //模板导入
  fileUpload() {
    //  console.log(111);
    this.isShowFile = false;
    var files = (document.getElementById("file0") as any).files[0];
    var fd = new FormData();
    fd.append("excelFile", files);
    (this as any).$services
      .importCameraExcel({
        data: fd,
        method: "post",
        processData: false,
        contentType: false,
        fromdata: true,
      })
      .then((result: any) => {
        this.$message({
          showClose: true,
          message: "导入成功",
          type: "success",
        });
        this.init();
        this.isShowFile = true;
      })
      .catch((err: any) => {
        // console.log(err);
        this.$message({
          showClose: true,
          message: err.msg,
          type: "warning",
        });
        this.isShowFile = true;
      });
  }
  // 模板下载
  templateDownload(): void {
    // console.log("模板下载");
    var a = document.createElement("a");
    a.download = name || "sxjpic";
    a.href = "/tzglMb/sxjmb.xlsx";
    a.click();
  }
  //远程维护
  remoteMaintenance(title, val) {
    // this.$confirm("20134654", title , {
    //   center: true,
    //   distinguishCancelAndClose: true,
    //   showCancelButton: false,
    //   showConfirmButton: false,
    // });
    const h = this.$createElement;
    this.$msgbox({
      title,
      center: true,
      distinguishCancelAndClose: true,
      showCancelButton: false,
      showConfirmButton: false,
      message: h("div", { style: {} }, [
        h(
          "p",
          { style: { display: title == "性能参数查看" ? "block" : "none" } },
          [
            h(
              "span",
              { style: { display: "inline-block", width: "50%" } },
              `CPU使用率: ${1}`
            ),
            h(
              "span",
              { style: { display: "inline-block", width: "50%" } },
              `网络负载率: ${1}`
            ),
            h(
              "span",
              {
                style: {
                  display: "inline-block",
                  width: "50%",
                  "margin-top": "0.3rem",
                },
              },
              `内存使用率: ${1}`
            ),
            h(
              "span",
              {
                style: {
                  display: "inline-block",
                  width: "50%",
                  "margin-top": "0.3rem",
                },
              },
              `磁盘使用率: ${1}`
            ),
          ]
        ),
        h(
          "p",
          { style: { display: title == "远程维护" ? "block" : "none" } },
          "远程维护..."
        ),
      ]),
    });
  }
  //初始查询
  init() {
    var from = {
      areaName: this.formData.substation,
      cameraName: this.formData.system,
      manufacturer: this.formData.manufacturer,
      page: this.pages.page,
      size: this.pages.pageSize,
      station: this.formData.cities,
      videoType: this.formData.sccj,
    };
    from.station = this.bdzId;

    (this as any).$services
      .queryVideo({ data: from, method: "post" })
      .then((result: any) => {
        console.log("数据数据", result);
        // let tableData = result.data.records || [{cehi: '测试'}];
        let tableData = [{ ceshi: "测试" }];
        let page = this.pages.page;
        let size = this.pages.pageSize;
        // if (tableData && tableData.length) {
        //   tableData.forEach((v, i) => {
        //     // console.log(v)
        //     v.scrq = time(v.scrq) || "";
        //     v.tcsj = time(v.tcsj) || "";
        //     v.tysj = time(v.tysj) || "";

        //     v.myIndex = (page - 1) * size + i + 1;
        //   });
        // }
        this.tableData = tableData;
        this.pages.totalSize = result.data.total;
      })
      .catch((err: object) => {
        this.tableData = [];
        console.log(err);
      });
    this.formData.cities = this.bdzId;
  }

  bdzxl() {
    //变电站下拉
    (this as any).$services
      .getStationList({ data: { ssds: this.treeSbSsdsId } })
      .then((result: any) => {
        this.bdzmc = result.data;
        // console.log(result);
      })
      .catch((err: object) => {
        console.log(err);
      });
  }
  mounted() {
    this.init();
  }
  @Watch("treeId", { immediate: true, deep: true })
  public treeIdDisplay(to: any, from: any) {
    if (this.Treeid == "area") {
      this.formData.areaName = this.id;
      this.formData.substation = this.id;
    }
    if (this.Treeid == "station") {
      this.formData.areaName = "";
      this.formData.substation = "";
    }
    if (this.Treeid == "station" || this.Treeid == "area") {
      this.formData.cities = this.bdzId;
      this.pages.pageSize = 10;
      this.pages.page = 1;
      this.init();
      this.bdzxl();
    }
  }
}
</script>
<style lang="scss">
.el-message-box__header {
  padding-top: 10px !important;
  border-bottom: 2px solid rgb(170, 164, 164);
}
</style>
<style lang="scss" scoped>
.RightFzjkDetails {
  width: 100%;
  height: 100%;
  .elForm-box {
    padding: 0.24rem 0.2rem 0 0;
    // margin-bottom: 0.2rem;
  }
  .inspection-report-index-btn {
    display: flex;
    padding-left: 0.46rem;
    padding-top: 0.02rem;
    margin-bottom: 0.1rem;
    .el-button + .el-button {
      margin-left: 0.1rem;
    }
  }
  .tableed {
    width: 100%;
    height: calc(100% - 2.01rem);
  }
  .paged {
    width: 100%;
    height: 0.6rem;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .buttom-box {
    display: flex;
    justify-content: center;
    align-items: center;
    > .el-button {
      margin: 0 0.6rem;
    }
  }
  .box {
    width: 100%;
    height: 100%;
  }
  #file0 {
    display: none;
  }
}
</style>
<style lang="scss">
.RightFzjkDetails {
  .inspection-report-index-btn {
    .el-button {
      padding: 0.12rem 0.2rem;
    }
  }
  .el-form-item {
    margin-bottom: 0.22rem;
  }
  .el-form-item--medium .el-form-item__content,
  .el-form-item--medium .el-form-item__label {
    line-height: 0.36rem;
  }
  .popUp-from {
    .el-form-item {
      margin-bottom: 0.35rem;
    }
  }
  // .el-dialog {
  //   // height: 5.88rem;
  // }
  .el-dialog__body {
    height: calc(100% - 44px);
  }
  //导入
  .el-upload-list {
    display: none;
  }
  .el-upload {
    margin: 0 0.1rem;
  }
}
</style>
